﻿using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using Hangjing.DBUtility;
using Hangjing.Model;

namespace Hangjing.SQLServerDAL
{
    /// <summary>
    /// 骑士上下线记录（上下班）
    /// </summary>
    public partial class DeliverWorkLog
    {

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(DeliverWorkLogInfo model)
        {
            SqlParameter[] parameters = 
			{
			    new SqlParameter("@deliverid", SqlDbType.Int,4) ,            
                new SqlParameter("@optime", SqlDbType.DateTime) ,            
                new SqlParameter("@optype", SqlDbType.Int,4) ,                     
              
            };

            parameters[0].Value = model.deliverid;
            parameters[1].Value = model.optime;
            parameters[2].Value = model.optype;

            SQLHelper.ExecuteNonQuery(CommandType.StoredProcedure, "DeliverWorkLog_add", parameters);

            return 1;
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(DeliverWorkLogInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update DeliverWorkLog set ");

            strSql.Append(" deliverid = @deliverid , ");
            strSql.Append(" optime = @optime , ");
            strSql.Append(" optype = @optype , ");
            strSql.Append(" reveint = @reveint , ");
            strSql.Append(" revevar = @revevar  ");
            strSql.Append(" where LID=@LID ");

            SqlParameter[] parameters = 
			{
			    new SqlParameter("@LID", SqlDbType.Int,4) ,            
                new SqlParameter("@deliverid", SqlDbType.Int,4) ,            
                new SqlParameter("@optime", SqlDbType.DateTime) ,            
                new SqlParameter("@optype", SqlDbType.Int,4) ,            
                new SqlParameter("@reveint", SqlDbType.Int,4) ,            
                new SqlParameter("@revevar", SqlDbType.VarChar,256)             
              
            };

            parameters[0].Value = model.LID;
            parameters[1].Value = model.deliverid;
            parameters[2].Value = model.optime;
            parameters[3].Value = model.optype;
            parameters[4].Value = model.reveint;
            parameters[5].Value = model.revevar;
            return SQLHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        }


        /// <summary>
        /// 获取记录所有字段
        /// </summary>
        /// 此代码由杭景科技代码内部生成器自动生成
        /// <param>LID</param>
        /// <returns>DeliverWorkLogInfo</returns>
        public DeliverWorkLogInfo GetModel(int LID)
        {
            string sql = "select LID,deliverid,optime,optype,reveint,revevar from DeliverWorkLog where  LID = @LID";
            SqlParameter parameter = new SqlParameter("@LID", SqlDbType.Int, 4);
            parameter.Value = LID;
            DeliverWorkLogInfo model = null;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.Text, sql, parameter))
            {
                if (dr.Read())
                {
                    model = new DeliverWorkLogInfo();
                    model.LID = HJConvert.ToInt32(dr["LID"]);
                    model.deliverid = HJConvert.ToInt32(dr["deliverid"]);
                    model.optime = HJConvert.ToDateTime(dr["optime"]);
                    model.optype = HJConvert.ToInt32(dr["optype"]);
                    model.reveint = HJConvert.ToInt32(dr["reveint"]);
                    model.revevar = HJConvert.ToString(dr["revevar"]);
                }
            }
            return model;
        }

        /// <summary>
        /// 获得总记录数
        /// </summary>
        /// 此代码由杭景科技代码内部生成器自动生成
        public int GetCount(string strWhere)
        {
            return (int)SQLHelper.ExecuteScalar(CommandType.StoredProcedure, "pagecount", new SqlParameter("@tblName", "DeliverWorkLog"), new SqlParameter("@strWhere", strWhere));
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pagesize">页尺寸</param>
        /// <param name="pageindex">页索引</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="orderName">排序字段</param>
        /// <param name="orderType">排序类型，1为降序，0为升序</param>
        /// <returns>图书列表</returns>
        ///此代码由杭景科技代码内部生成器自动生成
        public IList<DeliverWorkLogInfo> GetList(int pagesize, int pageindex, string strWhere, string orderName, int orderType)
        {
            IList<DeliverWorkLogInfo> infos = new List<DeliverWorkLogInfo>();
            SqlParameter[] parameters = 
			{
				new SqlParameter("@tblName", SqlDbType.VarChar,255),
				new SqlParameter("@strGetFields", SqlDbType.VarChar,1000),
				new SqlParameter("@primary", SqlDbType.VarChar,255),
				new SqlParameter("@orderName", SqlDbType.VarChar,255),
				new SqlParameter("@PageSize", SqlDbType.Int),
				new SqlParameter("@PageIndex", SqlDbType.Int),
				new SqlParameter("@OrderType", SqlDbType.Bit),
				new SqlParameter("@strWhere", SqlDbType.VarChar,1500)
			};
            parameters[0].Value = "DeliverWorkLog";
            parameters[1].Value = "*,(select name from Deliver where dataid = DeliverWorkLog.deliverid) as delivername";
            parameters[2].Value = "LID";
            parameters[3].Value = orderName;
            parameters[4].Value = pagesize;
            parameters[5].Value = pageindex;
            parameters[6].Value = orderType;
            parameters[7].Value = strWhere;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.StoredProcedure, "pageselectpri", parameters))
            {
                while (dr.Read())
                {
                    DeliverWorkLogInfo info = new DeliverWorkLogInfo();
                    info.LID = HJConvert.ToInt32(dr["LID"]);
                    info.deliverid = HJConvert.ToInt32(dr["deliverid"]);
                    info.optime = HJConvert.ToDateTime(dr["optime"]);
                    info.optype = HJConvert.ToInt32(dr["optype"]);
                    info.reveint = HJConvert.ToInt32(dr["reveint"]);
                    info.revevar = HJConvert.ToString(dr["revevar"]);
                    info.delivername = HJConvert.ToString(dr["delivername"]);
                    infos.Add(info);
                }
            }
            return infos;
        }

        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="Id"></param>
        /// 此代码由杭景科技代码内部生成器自动生成
        /// <returns></returns>
        public int DelDeliverWorkLog(int Id)
        {
            StringBuilder str = new StringBuilder();
            str.Append("delete from DeliverWorkLog where LID=@LID");
            SqlParameter[] Para = 
			{
				new SqlParameter("@LID",SqlDbType.Int)
			};
            Para[0].Value = Id;

            return SQLHelper.ExecuteNonQuery(CommandType.Text, str.ToString(), Para);
        }


        /// <summary>
        /// 批量删除记录
        /// </summary>
        /// <param name="IdList"></param>
        /// <returns></returns>
        /// 此代码由杭景科技代码内部生成器自动生成
        public int DelList(string IdList)
        {
            StringBuilder str = new StringBuilder();
            str.Append("delete from DeliverWorkLog where LID in ({0})");

            return SQLHelper.ExecuteNonQuery(CommandType.Text, string.Format(str.ToString(), IdList), null);
        }


    }
}

